package com.zmj.config;

import com.zmj.interceptor.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//@Component
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        //拦截所有请求
//        String[] addPathPatterns = {"/**"};
//        //不需要拦截的请求
//        String[] excludePathPatterns = {"/page/logout","/page/login","/page/init","/reader/login"};
//        registry.addInterceptor(new MyInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
//        super.addInterceptors(registry);
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        String[] addPathPatterns = {"/user/test","/user/testgetInfo"};  //需要拦截的路径

        registry.addInterceptor(new JWTInterceptor())
//                .addPathPatterns("/user/test")
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns("/user/login");
//                .excludePathPatterns("/user/login");
    }
}
